package com.hayden.fileMonitor.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogbackUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogbackUtil.class);
    public static void setLogLevel() {
        ConfigFileReader reader = new ConfigFileReader();
        // 从配置文件中获取日志级别
        String levelStr = reader.getProperty("log.level", "INFO");
        // 将日志级别转换为Logback的Level对象
        ch.qos.logback.classic.Level level = ch.qos.logback.classic.Level.toLevel(levelStr);
        // 设置根Logger的日志级别
        ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        rootLogger.setLevel(level);
        // 记录一条日志，查看日志级别是否已经生效
        LOGGER.info("日志级别设置为：{}",levelStr);
    }
}
